home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3344 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  59 lines

  1. Path: news.pi.se!usenet
  2. From: delenn@babcom.space.com (Satai Delenn)
  3. Newsgroups: comp.lang.c++
  4. Subject: Pointers HELP!!!!
  5. Date: Tue, 23 Jan 1996 22:23:35 GMT
  6. Message-ID: <31055e1d.1020193@news.pi.se>
  7. NNTP-Posting-Host: d406.sth.pi.se
  8. Mime-Version: 1.0
  9. Content-Type: text/plain; charset=iso-8859-1
  10. Content-Transfer-Encoding: 8bit
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. Hia!
  14.  
  15. What I want to do is to pass a pointer to a member function to another
  16. object, which later will call this function thru this pointer.
  17.  
  18. What I did:
  19.  
  20. ////////////////////////////////////////////////////
  21. typedef void(*PFUNC)(int);
  22. ////////////////////////////////////////////////////
  23. class A
  24. {
  25. public:
  26.     void callback(int error) {
  27.         /* Something */;
  28.     }
  29.  
  30.     B* pB;
  31. public:
  32.     A() {
  33.         pB = new B(A::callback);
  34.     };
  35.     ~A() {
  36.         delete pB;
  37.     };
  38. };
  39. ////////////////////////////////////////////////////
  40. class B
  41. {
  42. public:
  43.     PFUNC m_callback;
  44. public:
  45.     B(PFUNC callback) {
  46.         m_callback = callback;        
  47.         *m_callback(10);
  48.     }    
  49.     ~B(){};
  50. };
  51. ////////////////////////////////////////////////////
  52.  
  53. I know this doesnt work, so please ne1 help me out here.
  54.  
  55. // thomas@mediamatic.se
  56.  
  57.  
  58.  
  59.